/**
 * 
 */
package l1j.opqlo.假人系統;

import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.LineNumberReader;

/**
 * @author user
 *
 */
public class FileInputStream
{
	private File file;
	private String text;
	
	/** @return 讀取到的文字 */
	public final String getText()
	{
		return text;
	}

	public FileInputStream(File file)
	{
		this.file = file;
	}
	
	public final void loadFiles() throws IOException
	{
		for (File f : file.listFiles())
		{
			loadFile(f);
		}
	}
	
	public final void loadFile() throws IOException
	{
		loadFile(file);
	}
	
	private final void loadFile(File f) throws IOException
	{
		LineNumberReader lnr = null;
		text = new String("");
		
		try
		{
			lnr = new LineNumberReader(new FileReader(f));
			
			while (lnr.ready())
			{
				String temp = lnr.readLine();
				temp = temp.substring(0, temp.indexOf('#'));
				
				if (temp.length() > 0)
				{
					text += lnr.readLine() + "\r\n";
				}
			}
		}
		catch (IOException e)
		{
			e.printStackTrace();
		}
		finally
		{
			if (lnr != null)
			{
				try
				{
					lnr.close();
				}
				catch (IOException e)
				{
				}
				
				lnr = null;
			}
		}
	}
}
